package com.example.onlinemusic.mapper;

import com.example.onlinemusic.model.Music;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MusicMapper {
    /**
     * 插入音乐到数据库
     * @param title
     * @param singer
     * @param time
     * @param url
     * @param userid
     * @return
     */
    @Insert("insert into music(title,singer,time,url,userid) values(#{title},#{singer},#{time},#{url},#{userid})")
    int insert(String title, String singer, String time,String url,int userid);

    /**
     * 音乐存入数据库之前，先查询一下有没有
     */
    @Select("select * from music where title=#{title} and singer=#{singer}")
    Music check(String title,String singer);

    @Select("select * from music where id=#{id}")
    Music findMusicById(@Param("id") Integer musicId);

    /**
     * 删除当前 id 的音乐
     */
    @Delete("delete from music where id=#{id}")
    int deleteMusicById(@Param("id") int musicId);

    @Select("select * from music")
    List<Music> findMusic();

    @Select("select * from music where title like concat('%',#{title},'%')")
    List<Music> findMusicByName(@Param("title") String musicName);


}
